package com.twu.biblioteca.ui;

import com.twu.biblioteca.data.BibliotecaItem;
import com.twu.biblioteca.data.BibliotecaItemDAO;
import com.twu.biblioteca.data.User;
import com.twu.biblioteca.exceptions.ItemNotCheckedOutException;

/**
 * Created by florian on 27/12/13.
 */
public class ReturnController extends ControllerWithItem {
    private final User user;

    public ReturnController(ScreenControllerFactory controllerFactory, BibliotecaUI ui, BibliotecaItemDAO dao, User user) {
        super(controllerFactory, ui, dao);
        this.user = user;
    }

    @Override
    protected void showUsage() {
        ui.showReturnMessage();
    }

    @Override
    protected ScreenController handleWithItem(BibliotecaItem item) throws ItemNotCheckedOutException {
        dao.returnItem(item);
        ui.showSuccessfulReturnMessage();
        return controllerFactory.createMainScreenControllerLoggedIn(user);
    }
    @Override
    protected ScreenController handleError() {
        ui.showUnsuccessfulReturnMessage();
        return this;
    }
}
